public class Solution641 {

    int[] queue;
    int size;
    int l,r;

    public Solution641(int k) {
        queue=new int[k];
        size=0;
        l=0;
        r=0;
    }

    public boolean insertFront(int value) {
        if (size==queue.length){
            return false;
        }
        if (size==0){
            l=r=0;
            queue[0]=value;
        }else {
            l = (l - 1 + queue.length) % queue.length;
            queue[l] = value;
        }
        size++;
        return true;
    }

    public boolean insertLast(int value) {
        if (size==queue.length){
            return false;
        }
        if (size==0) {
            l=r=0;
            queue[0]=value;
        }else{
            r = (r + 1) % queue.length;
            queue[r] = value;

        }
        size++;
        return true;
    }

    public boolean deleteFront() {
        if (size==0){
            return false;
        }
        l=(l+1)%queue.length;
        size--;
        return true;
    }

    public boolean deleteLast() {
        if (size==0){
            return false;
        }
        r=(r-1+queue.length)%queue.length;
        size--;
        return true;
    }

    public int getFront() {
        if (size==0){
            return -1;
        }
        return queue[l];
    }

    public int getRear() {
        if (size==0){
            return -1;
        }
        return queue[r];
    }

    public boolean isEmpty() {
        return size==0;
    }

    public boolean isFull() {
        return size==queue.length;
    }

    public static void main(String[] args) {
        Solution641 solution641=new Solution641(3);
        System.out.println(solution641.insertLast(1));
        System.out.println(solution641.insertLast(2));
        System.out.println(solution641.insertFront(3));
        System.out.println(solution641.insertFront(4));
        System.out.println(solution641.getRear());
        System.out.println(solution641.isFull());
        System.out.println(solution641.deleteLast());
        System.out.println(solution641.insertFront(4));
        System.out.println(solution641.getFront());
    }
}
